package com.lanhe.admin.controller.product;

import com.lanhe.common.annotation.Log;
import com.lanhe.common.core.controller.BaseController;
import com.lanhe.common.core.domain.AjaxResult;
import com.lanhe.common.core.page.TableDataInfo;
import com.lanhe.common.enums.BusinessType;
import com.lanhe.product.domain.LhKayuProduct;
import com.lanhe.product.service.ILhKayuProductService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 卡鱼产品表(LhKayuProduct)表控制层
 *
 * @author zhanggl
 * @since 2023-12-22 18:01:05
 */
@RestController
@RequestMapping("lhKayuProduct")
public class LhKayuProductController extends BaseController {

    /**
     * 服务对象
     */
    @Resource
    private ILhKayuProductService lhKayuProductService;

    /**
     * 分页查询所有数据
     */
    @PreAuthorize("@ss.hasPermi('product:lhKayuProduct:list')")
    @GetMapping("/list")
    public TableDataInfo list(LhKayuProduct product) {
        startPage();
        List<LhKayuProduct> list = lhKayuProductService.selectKayuProductList(product);
        return getDataTable(list);
    }

    /**
     * 根据编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:lhKayuProduct:query')")
    @GetMapping(value = {"/", "/{productId}"})
    public AjaxResult getInfo(@PathVariable(value = "productId") Long productId) {
        return success(lhKayuProductService.selectKayuProductById(productId));
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('product:lhKayuProduct:add')")
    @Transactional
    @Log(title = "卡鱼产品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody LhKayuProduct product) {

        product.setCreateBy(getUsername());
        product.setCreateTime(new Date());
        return toAjax(lhKayuProductService.insertKayuProduct(product));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('product:lhKayuProduct:edit')")
    @Log(title = "卡鱼产品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody LhKayuProduct product) {
        if (ObjectUtils.isEmpty(product.getProductId())
                || null == product.getProductId()) {
            return error("主键ID不能为空");
        }
        product.setUpdateBy(getUsername());
        product.setUpdateTime(new Date());
        return toAjax(lhKayuProductService.updateKayuProduct(product));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('product:lhKayuProduct:remove')")
    @Log(title = "卡鱼产品管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable Long[] productIds)
    {
        if (ObjectUtils.isEmpty(productIds)){
            return error("主键ID不能为空");
        }
        return toAjax(lhKayuProductService.deleteKayuProductByIds(productIds));
    }
}

